//
// Created by 11510 on 2025/10/2.
//

#pragma once
#include "ICommand.h"
#include "CommandContext.h"
#include <string>
#include <memory>
#include <unordered_map>
#include <functional>
namespace xclib_client {
    using CommandCreator = std::function<std::unique_ptr<ICommand>(CommandContext)>;
    class CommandFactory {
    public:
        static CommandFactory &instance();

        void registerCommand(const std::string &name, CommandCreator creator) ;

        bool has(const std::string &name) const ;

        std::unique_ptr<ICommand> create(const std::string &name, CommandContext ctx) const ;

        std::vector<std::string> listCommands() const ;

    private:
        std::unordered_map<std::string, CommandCreator> registry;
    };
}

